package com.dragon.design.pattern.creational.singleton;

import java.io.Serializable;

/**
 * 饿汉式单例设计模式
 *
 * @author dragon
 * @version V1.0.0-RELEASE
 * @date 2019/5/15 21:26
 */
public class HungarySingleton implements Serializable {

    private static HungarySingleton hungarySingleton = new HungarySingleton();

    private HungarySingleton() {
        if (hungarySingleton != null) {
            throw new RuntimeException("单例构造器禁止反射调用");
        }
    }

    public static HungarySingleton getInstance() {
        return hungarySingleton;
    }

    public Object readResolve() {
        return hungarySingleton;
    }
}
